<?php

/**
 * Project form base class.
 *
 * @package    acap
 * @subpackage form
 * @author     Your name here
 */
abstract class BaseFormPropel extends sfFormPropel
{

    public function setup()
    {

    }

    public function getFormName()
    {
        $name = parent::getFormName();
        if (is_null($name))
        {
            $name = strtolower($this->getModelName());
        }

        return $name;
    }

    public function bindAndSave($values)
    {
        if ($values instanceof sfRequest)
        {
            $formName = $this->getFormName();
            if ($formName !== null)
            {
                $values = $values->getParameter($formName);
            }
            else
            {
                $values = $values->getParameterHolder()->getAll();
            }
        }

        return parent::bindAndSave($values);
    }

    /**
     * This method can be customized.
     *
     * @param array $values
     */
    protected function _updateObject($values)
    {
        return $values;
    }

    /**
     * NOT OVERRIDABLE!
     *
     * @param type $values
     */
    final protected function doUpdateObject($values)
    {
        $values = $this->_updateObject($values);

        parent::doUpdateObject($values);
    }

}
